/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package SteamEngineFX.data;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author jbendixsen
 */
public class SteamEngineConnection {
    
    private EntityManagerFactory emf;
    private String unitName;
    
    public SteamEngineConnection (String UnitName){

        //store the unit name
        unitName = UnitName;
        
        //create EM factory
        System.out.println("Starting SteamEngineConnection " + UnitName);
        try
        {
            
        emf = Persistence.createEntityManagerFactory(unitName);
        } catch(RuntimeException ex){
            System.out.println("Error connecting to database: "+ex.getMessage());
            throw ex;
        }
        
    }
    
    public EntityManager getConnection(){
        //create a new EM, caller takes some responsibility in managing the resource
        return emf.createEntityManager();
    }
    
    public String getUnitName(){
        return unitName;
    }
    
}
